package nl.weeaboo.sh.objects;

import java.awt.Rectangle;

import nl.weeaboo.sh.Game;
import nl.weeaboo.sh.level.Tile;
import nl.weeaboo.sh.model.DamageRect;

public class ShotCollidable implements Collidable {

	private Game game;
	private Shot shot;
	
	public ShotCollidable(Game g, Shot s) {
		game = g;
		shot = s;
	}
	
	//Functions
	public void onCollision(Sprite attacker, Sprite defender, Rectangle hitArea, int dmg, DamageRect dr) {
		onSplashCollision(attacker, defender, hitArea, dmg, dr);
	}
	public void onSplashCollision(Sprite attacker, Sprite defender, Rectangle hitArea, int dmg, DamageRect dr) {
		if (shot == attacker) {
			if (defender.damage(dmg)) {
				game.getSoundManager().playSound("impact.wav", 1);
			}
			attacker.destroy();
		} else if (shot == defender) {
			shot.damage(dmg);
		}
	}
	public void onCollision(Sprite attacker, Tile damaged, Rectangle hitArea, int dmg) {
		damaged.damage(dmg);
		attacker.destroy();
	}
	public void onCollision(Tile attacker, Sprite damaged, Rectangle hitArea, int dmg) {
		//Tiles can't hurt shots
	}

	//Getters
	public boolean getCollidesDamage(Sprite s) {
		return false;
	}
	public boolean getCollidesSplash(Sprite s) {
		if (s == shot) return false;
		if (s == shot.getOwner()) return false;
		if (s instanceof Shot) return false;
		if (s instanceof Platform) return false;

		return true;
	}

	public Shot getSprite() { return shot; }
	
	//Setters
	
}
